<?php
/**
 * Created by PhpStorm.
 * User: WINNERWLY
 * Date: 2018/7/30
 * Time: 14:27
 */

namespace app\index\controller;

use app\index\model\User;
use think\Controller;

class Todo extends Controller
{
    /**
     * 分页查询
     * $page     分页页数
     * $rows     分页显示的条数
     **/
    public function index()
    {
        $query = input();
        $model = new User();
        $res = $model
//            ->field("id,name,sex,sexText")
            ->where("is_delete != 1")
            ->page($query['page'], $query['rows'])
            ->select();
        $total = $model
            ->field("id,name")
            ->where("is_delete != 1")
            ->count();
        return ajaxReturn(200, "查询成功", $res, $total);
    }

    public function add()
    {
        $model = new User();
        $res = $model->save([
            "name" => 123,
        ]);
        if ($res) {
            return ajaxReturn(200, "新增成功");
        } else {
            return ajaxReturn(201,  "新增失败");
        }
    }

    public function update()
    {

    }

    public function delete()
    {
        $query = input();
        $res = User::destroy($query['ids']);

        dump($res);
    }
}
